﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Security.Principal;
using Microsoft.Reporting.WebForms;
using System.Net;

namespace Crosland.Automotriz.Web.Popup
{
    public partial class ConcentracionClientesPopup : BaseForm
    {
        protected override void Inicializar()
        {

            this.rvPopupReporte.ProcessingMode = ProcessingMode.Remote;
            this.rvPopupReporte.ShowCredentialPrompts = true;
            this.rvPopupReporte.ShowExportControls = true;
            this.rvPopupReporte.ServerReport.ReportServerCredentials = new RSCredentials();
            this.rvPopupReporte.ServerReport.ReportServerUrl =
                new Uri(ConfigurationManager.AppSettings[DatosConfiguracion.RsServer]);
            this.rvPopupReporte.ServerReport.ReportPath = "/SAP_REPUESTOS/rs_REP_ClientesABC";

            //base.Inicializar();
        }

        [Serializable]
        public sealed class RSCredentials : IReportServerCredentials
        {
            public WindowsIdentity ImpersonationUser
            {
                get { return null; }
            }

            public ICredentials NetworkCredentials
            {
                get
                {
                    string userName = ConfigurationManager.AppSettings[DatosConfiguracion.RsUser];
                    string password = ConfigurationManager.AppSettings[DatosConfiguracion.RsPassword];
                    string domain = ConfigurationManager.AppSettings[DatosConfiguracion.RsDomain];

                    return new NetworkCredential(userName, password, domain);
                }
            }

            public bool GetFormsCredentials(out Cookie authCookie, out String userName, out String password,
                out String authority)
            {
                authCookie = null;
                userName = null;
                password = null;
                authority = null;
                return false;
            }
        }

        protected void btnSalir_Click(object sender, EventArgs e)
        {
            string script = "CerrarVentana();";
            ScriptManager.RegisterStartupScript(this, typeof(Page), "cerrar", script, true);
        }
    }
}